﻿#region Copyright
// Copyright (c) 2011-2012 RaisingForce Team (Alikin Sergey)
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System.Diagnostics.Contracts;

namespace RaisingForce.RaiseHardwareTest.ViewModel.MainStates
{
    internal abstract class MainState :
        IMainState
    {
        #region Constructors

        protected MainState(
            string statusText,
            string doneStateKey = null,
            bool isConnected = false,
            bool isConnecting = false,
            bool isDisconnected = false,
            bool isEngineRunning = false)
        {
            Contract.Requires(statusText != null);
            this.statusText = statusText;
            this.doneStateKey = doneStateKey;
            this.isConnected = isConnected;
            this.isConnecting = isConnecting;
            this.isDisconnected = isDisconnected;
            this.isEngineRunning = isEngineRunning;
        }

        #endregion

        #region Private Declarations

        private readonly string statusText;

        private readonly bool isConnected;

        private readonly bool isConnecting;

        private readonly bool isDisconnected;

        private readonly bool isEngineRunning;

        private readonly string doneStateKey;

        [ContractInvariantMethod]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
        private void ObjectInvariant()
        {
            Contract.Invariant(this.statusText != null);
        }


        #endregion

        #region IMainState Members

        public virtual void ConnectHardware(
            MainViewModel viewModel,
            MainViewModelData viewModelData)
        {
            // do nothing
        }

        public virtual void DisconnectHardware(
            MainViewModel viewModel,
            MainViewModelData viewModelData)
        {
            // do nothing
        }

        public string StatusText
        {
            get { return this.statusText; }
        }

        public string DoneStateKey
        {
            get { return this.doneStateKey; }
        }

        public bool IsConnected
        {
            get { return this.isConnected; }
        }

        public bool IsConnecting
        {
            get { return this.isConnecting; }
        }

        public bool IsDisconnected
        {
            get { return this.isDisconnected; }
        }

        public bool IsEngineRunning
        {
            get { return this.isEngineRunning; }
        }

        #endregion
    }
}
